//处理备文件内容请求
//获取app对象
var express = require('express')
	//导入 upload对象
var fs = require('fs');
var template = require('../module/template.js');
var router = express.Router();
router.get('/detail',function(req,res){
	console.log(req.query.title)
	console.log(req.query.name)
	res.render('detail',{title:req.query.title,detail:req.query.name});
})
//处理添加操作
router.post('/Content/addContent', function(req, res) {
	// 读取文件内容
	fs.readFile('infos/infos.txt', function(err, data) {
		data = JSON.parse(data);
		if(!err) {
			for(var i = 0; i < data.length; i++) {
				if(data[i].folder == req.body.title) {
					var obj = {};
					obj.name = req.body.content
					obj.time = (new Date()).getTime();
					data[i].contents.push(obj);
					break;
				}
			}
			//放入修改过的
			fs.writeFile('infos/infos.txt', JSON.stringify(data), function(err) {
				if(!err) {
					//写入成功
						res.status(200).send({
							code:1,
							message:'添加成功'
						});
				}
			});
		}
	});
});
//导出备忘录文件夹对象
module.exports = router;